/**
 * 优化性能
 */
#include <vector>
#include <iostream>
#include <string>
#include <utility>

struct S {
    std::string a{"0"};
    S() {
        std::cout << "new: " << a << std::endl;
    }

    S(int a_) : a(std::to_string(a_)) {
        std::cout << "new: " << a_ << std::endl;
    }

    ~S() {
        std::cout << "del: " << a << std::endl;
    }
};

int main() {
    std::vector<S> vec;
    for (int i = 1; i < 5; i++) {
        S s{i};
        vec.emplace_back(s);
    }
    std::cout << std::string(10, '=') << std::endl;
    std::vector<S> vec0;
    for (int i = 1; i < 5; i++) {
        S s{i};
        vec0.emplace_back(std::move(s));
    }
    std::cout << std::string(10, '=') << std::endl;
    std::vector<S> vec1;
    for (int i = 1; i < 5; i++) {
        vec1.emplace_back(i);
    }
    std::cout << std::string(10, '=')  << "!!!" << std::endl;
    std::vector<S> vec2;
    S s1;
    for (int i = 5; i < 9; i++) {
        s1.a = std::to_string(i);
        vec2.emplace_back(s1);
    }
    std::cout << std::string(10, '=') << std::endl;
    std::cout << "vec2:" << std::endl;
    for (const auto &s: vec2) {
        std::cout << s.a << std::endl;
    }
    std::cout << std::string(20, '*') << std::endl;
    return 0;
}